﻿using System;

namespace Ops.Mpc.ValidationServices.Attributes
{
    [AttributeUsage(AttributeTargets.Property)]
    public class RequiredNumberAttribute : ValidationAttribute
    {
        public RequiredNumberAttribute()
        {
            this.Minimum = int.MinValue;
            this.Maximum = int.MaxValue;
        }

        public override bool Validate(object container, object data, string[] propertyNames)
        {
            int? number = data as int?;

            return number.HasValue && number <= Maximum && number >= Minimum;
        }

        public override string FormatMessage(string messageFormat, object container, object data, string name)
        {
            return string.Format(messageFormat, data, Minimum, Maximum);
        }

        public int Maximum
        {
            get;
            set;
        }

        public int Minimum
        {
            get;
            set;
        }
    }
}
